<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录-考拉海购</title>
    <link rel="stylesheet" href="css/other.css">
    <link rel="stylesheet" href="css/common.css">

    <script src="js/cookie.js"></script>
    <script src="js/ajax.js"></script>

</head>

<body>
    <div id="dl_header_wrap">
        <div id="dl_header">
            <div class="zc_header_left"></div>
            <div class="zc_header_right"></div>

        </div>
    </div>
    <div id="dl_contain">
        <div class="zc_contain_one"></div>
        <div class="zc_contain_two">
            <h2>手机号登录</h2>
            <input type="text" placeholder="请输入正确的手机号">
            <span class="tsnr"></span>
            <input type="password" placeholder="请输入密码">
            <input type="button" value="登录" id="zc_btn">
            <span>
                <ul></ul>
            </span>
        </div>
    </div>
    <div id="dl_footer">
        <div id="footer">
            <div id="footer_three_four_wrap">
                <div class="footer_three">
                    <div class="footer_three_one">
                        <span>增值电信业务经营许可证：浙B2-20160288</span>
                        <span>（浙）网械平台备字[2018]第00007号</span>
                        <span>阿里巴巴版权所有©2003-2021</span>
                        <span><a href="">隐私政策</a>
                            <span>-</span>
                            <a href="">考拉海购</a></span>
                    </div>
                    <div class="footer_three_two">
                        <span>网络文化经营许可证：浙网文（2020）4340-180号</span>
                        <span>浙江省网络食品销售第三方平台提供者备案：浙网食A33010006</span>
                    </div>
                    <div class="footer_three_three">
                        <a href=""><img src="img/footer/ga.png" alt=""></a>
                        <a>浙公网安备 33010802002216号</a>
                        <a href="">互联网药品信息服务资格证书编号（浙）-2017-0027</a>
                        <a href="">浙ICP备16011229号</a>
                        <a href="">自营经营者信息</a>
                    </div>

                    <div class="footer_three_four">
                        <span><img src="img/footer/flast2.png" alt=""></span>
                        <b><img src="img/footer/flast1.png" alt=""></b>
                    </div>
                </div>
            </div>
        </div>

    </div>



    <script>
        let oInput = document.querySelectorAll("input");
        let oSpan = document.querySelector("span")
        oInput[2].onclick = function () {

            let oPhone = oInput[0].value;
            console.log(oPhone.length)
            var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
            if (oPhone.length == 0) {
                oSpan.innerText = '手机号不能为空';
            }

            if (oPhone.length == 11 && !myreg.test(oPhone)) {
                oSpan.innerText = '请输入有效的手机号码！';
            }
            if (oPhone.length != 0 && oPhone.length != 11) {
                oSpan.innerText = '请输入11位有效的手机号码!';
            } else if (oPhone.length == 11 && myreg.test(oPhone)) {
                oSpan.innerText = '格式正确';
                let user = oInput[0].value
                let paw = oInput[1].value
                ajax({
                    method: "get",
                    url: ` http://jx.xuzhixiang.top/ap/api/login.php`,
                    params: {
                        username: user,
                        password: paw
                    },
                    success(obj) {
                        console.log(obj)
                        alert(obj.msg)
                        if (obj.code == 1) {
                            console.log(obj.data.token);
                            setCookie("token", obj.data.token, 7)
                            setCookie("username", user, 7)
                            // setCookie("token", obj.data.token, 7)
                            localStorage.setItem("uid", obj.data.id)
                            localStorage.setItem("token", obj.data.token)


                            console.log(getCookie("username"))
                            location.href = "index.html"

                            // uid: 47031
                            // token: 5835f9dd0d3bb14e4109bbd98bebb7d5

                        }
                    }
                })
            }


        }
    </script>

</body>

</html>